package com.zx.platform.zanadu.manager.util;

import org.bson.Document;
import org.bson.conversions.Bson;

import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Filters;

public class MongoDAO {
	
	public static void insertJson(String dbName,String collName,String json) {
		MongoCollection<Document> collection = MongoDBUtil.instance.getCollection(dbName, collName);
		Document doc = Document.parse(json);
		collection.insertOne(doc);
	}
	
	public static void updateByFilterKey(String dbName,String collName,String filterKey,String filterValue,String json) {
		MongoCollection<Document> collection = MongoDBUtil.instance.getCollection(dbName, collName);
		Document doc = Document.parse(json);
		
		Bson filter = Filters.eq(filterKey, filterValue);
		//collection.replaceOne(filter, doc); // 完全替代
		collection.updateOne(filter, new Document("$set", doc));
	}

}